GBML manual / Drawing

sprite_color_look

Gives ONE color of a sprite a different color on every row of the screen, so a flame can run from yellow to red or a crystal from white to blue. EVERY picture that uses that color changes, not only one object. spr is the sprite, color_number is which of its colors (1 and up), look is one of the SPRITECOLOR_ constants, strength (1 to 3) is how rich the colors are, and speed is how fast they slide down the screen. SPRITECOLOR_NONE turns it off.

Works differently on Game Boy - The Game Boy has no colors, so one color of a sprite changes its shade in bands (at most 6, each at least 28 rows tall), for every sprite that wears it; the look has to be named in the call.

Works differently on Game Boy Color - The Game Boy Color changes one color of a sprite's palette row by row, for every sprite that wears it; only one row-by-row color runs at a time (this, the backdrop or an overlay's Sky color), and the look has to be named in the call.

Sega Genesis: not built yet

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

sprite_color_look(spr, color_number, look, strength, speed)

Arguments

NameType
sprsprite
color_numberint
lookspritecolor_look
strengthint
speedreal

Returns

Nothing.

Description

Gives one color of a sprite a different color on every row of the screen. The red of a flame can run from pale yellow at the top of the screen to deep red at the bottom. The blue of a crystal can glitter from white to deep blue. A sprite's color is changed for as long as the look is on, and the sprite's own color comes back when you turn the look off.

A real capture, four pictures of the same striped lighthouse - first in its own colors, then with each of the three SPRITECOLOR_ looks in turn on its red stripes at strength 2 (the stripes turn green with the rainbow, orange with fire, and pale blue with ice)A real capture, four pictures of the same striped lighthouse - first in its own colors, then with each of the three SPRITECOLOR_ looks in turn on its red stripes at strength 2 (the stripes turn green with the rainbow, orange with fire, and pale blue with ice)
A real capture, four pictures of the same striped lighthouse - first in its own colors, then with each of the three SPRITECOLOR_ looks in turn on its red stripes at strength 2 (the stripes turn green with the rainbow, orange with fire, and pale blue with ice)

The lighthouse in its own colors, then each look at strength 2 on its red stripes, standing still. The lighthouse takes up only the middle of the screen, so it shows only that part of each look: the green of the rainbow, the orange of fire, the pale blue of ice. Real pictures from a Game Boy Advance ROM.

You give it five things:

Which look

LookWhat it is
SPRITECOLOR_RAINBOWred, yellow, green, blue and violet, from the top of the screen to the bottom
SPRITECOLOR_FIREpale yellow, orange, red and dark red
SPRITECOLOR_ICEwhite, pale cyan, blue and deep blue

Every picture that uses that color changes

The color belongs to the sprite's palette, not to one object. Every instance of the sprite changes, wherever it is. And the console keeps just one copy of any list of colors, so another sprite whose palette is the same list of colors changes too.

The colors belong to the rows of the screen, not to the sprite. A sprite that stands still has a stripe of every color in it. A sprite that walks down the screen passes through the colors, and is a different color at every height.

One look for each color

Each color of a sprite is its own look and holds its own row-by-row slot, so changing two colors of one sprite uses two slots. Asking for a different look or strength on the same color replaces the first and keeps the colors where they were. Asking again for the same look and strength only changes the speed.

Call it once

You do not need to call it every frame. Call it once - when the room starts is a good time - and the look keeps going by itself. A look belongs to the sprite, so there is nothing to remember and nothing to lose: it ends by itself when a room is loaded (you change room, or restart the one you are in), and the sprite's own color comes back with it.

Turning it off

sprite_color_look(spr_doc_hero, 3, SPRITECOLOR_NONE, 0, 0);

This gives its slot back straight away, and the sprite's own color comes back. The last two numbers are ignored, but they have to be there.

Always destroy it, do not hide it. There is no way to hide a look, on purpose: something hidden would look gone but would still be using up one of the console's few row-by-row slots, and then the next effect you ask for would not appear and nothing would tell you why. Off always means the slot is free.

What it costs

A look uses one of the 8 row-by-row effects the console has, and no matrix. A room change keeps two of the eight for itself, so there are six left for you, shared with everything else that works row by row: screen_backdrop, sprite_warp, draw_sprite_ripple and the others. You can see how many are in use on the debug screen: the line called H-BLANK.

It also holds the sprite's palette, one of the console's 16 sprite palettes, for as long as the look is on, even when no picture of the sprite is showing. A sprite that is already on the screen has its palette held already, so the look costs no more.

The patterns live in the cartridge, 640 bytes each, and a call that names its look keeps only that one. Measured on a real ROM, a look that stands still costs about 1 hundredth of a frame, and one that moves costs about 1.3 hundredths.

When there is no room

Ask for more than there is and the game does not skip it. A development build stops with a message that says how many slots there are and names every look that is holding one, so you know which one to turn off. It says so too if all 16 sprite palettes are in use and this sprite's cannot be held. A release build, which has no way to stop and show a message, draws the sprite in its own colors. It never half-works.

Example

sprite_color_look(spr_doc_hero, 3, SPRITECOLOR_FIRE, 2, 0.5);

Color number 3 of spr_doc_hero glows like fire, the colors sliding slowly down the screen. Call it in the Create event.

if (btn_pressed(BTN_A)) {
    sprite_color_look(spr_doc_hero, 3, SPRITECOLOR_ICE, 3, 0);
}

Pressing A turns the same color to ice, standing still. Pressing A again changes nothing, because it is the same look and strength.

On the GBA

Costs ONE of the console’s 8 row-by-row (H-Blank) effects for as long as the look is on, and no matrix. It also holds the sprite’s palette, one of the console’s 16, for as long as the look is on, even when no picture is showing. A room change keeps two of the eight for itself, so six are left for you, shared with everything else that works row by row. The look belongs to the sprite’s palette, not to one object: every instance of the sprite shares it, and so does any other sprite whose palette is the same list of colors, because the console keeps just one copy of a palette. Each color of a sprite is its own look: two colors are two row-by-row effects. The rows belong to the screen, so a sprite that moves down the screen passes through the colors. Color number 0 is the see-through color and cannot be changed; a number past the sprite’s last color is refused. The tables are in the cartridge (640 bytes each; a call with a look written out keeps only that one). A look stays until you turn it off or a room is loaded (a restart counts), and the sprite’s own color comes back when it ends. Turning it off with SPRITECOLOR_NONE hands the slot and the palette back at once, but hiding something does not: destroy it, do not hide it. If there is no room for another one, a development build stops with a message that names every look holding a slot; a release build draws the sprite in its own colors. The same happens when all 16 sprite palettes are in use and this sprite’s palette cannot be held. The in-game debug overlay shows the count as H-BLANK.

See also: sprite_warpsprite_distortscreen_backdropdraw_spritesprite